$(document).ready( function() {
	  var table = $('table#matsummReportTable').DataTable({
          initComplete: function(settings, json) {
              $("#matsummReportTable").removeClass('dataTable');
              $("#matsummReportTable").parent().addClass('table-responsive');

              $("#matsummReportTable").parent().height($(window).height()-$('#query-area').height()-230);

              $("#matsummReportTable").on('change', 'input[type="checkbox"]', function () {
                  if($(this).prop('checked')) {
                      $(this).closest('tr').addClass('warning');
                  } else {
                      $(this).closest('tr').removeClass('warning');
                  }
              });
          },
	    ajax: {
	      url: baseUrl + '/inventorymatsummDatatable',
	      data : function(d) {
			d.material = $("#material").val();
			return d;
	      }
	    },
	    order: [
	      [1, 'asc']
	    ],
	    columns: [{
	      name: 'materialcode',
	      data: 'materialcode'
	    },{
	      name: 'materialname',
	      data: 'materialname'
	    },{
	      name: 'summtranscount',
	      data: 'summtranscount'
        },{
          name: 'summtracecount',
          data: 'summtracecount'
	    },{
	      name: 'summcontaincount',
	      data: 'summcontaincount'
	    },{
		  name: 'summquantity',
		  data: 'summquantity'
	    }]
	  });

		  //导出 动态组织form提交
		  $(".btn.export").on("click", function (e) {
			$("#exportForm .param").remove();
			var $frm = $("#exportForm");
		　　　var array = $('.search-form').serializeArray();
		　　　for (i = 0, length = array.length; i < length; i++) {
			　　　key = array[i].name;
				value = array[i].value;
				$frm.append($('<input class="param" type="hidden" name = "' + key + '" value = "' + value + '" />')); 
			}
			var params = table.ajax.params();
			$frm.append($('<input class="param" type="hidden" name="input" value = \'' + JSON.stringify(params) + '\' />')); 
			$frm.submit();
			// 阻止默认行为
			e.preventDefault();
			return false;  
		  });
		  

		  $('.search-form').on("submit", function (e) {
		    table.draw();
		    //阻止表单submit
		    return false;
		  });
	
});
